import * as Vue from 'vue'

const { createApp } = Vue
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

//整合Element-plus
import * as ElementPlus from 'element-plus'
// import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import 'element-plus/dist/index.css'
import { useElIcon } from '@/utils/setGlobal'


//导入全局样式
import '@/styles/index.scss'

// 权限控制，动态路由
import '@/router/permission';
// @ts-ignore
import VueGridLayout from 'vue-grid-layout' // 引入layout


// 自定义指令
import { directive } from '@/directive';
import {markRaw} from "vue";
import {Session} from "@/utils/storage";

const app = createApp(App)
// @ts-ignore
define('vue', [], function (){return Vue})
// @ts-ignore
define('element-plus', [], function (){return ElementPlus})


const NODE_ENV = import.meta.env.MODE
// @ts-ignore
window.process = {env: {NODE_ENV}}

const loadRemote = () => { // 注册插件
    const url = Session.get('umdUrl')
    if(url) {
        url.forEach(ele => {
            // @ts-ignore
            requirejs([ele], (m: any) => {
                console.log(m)
                Object.keys(m).forEach(key => {
                    app.component(key,m[key])
                })
                // app.component('one', m.one)
                // app.component('tow', m.tow)
            })
        })
    }
    

}
loadRemote()

app.use(createPinia())
app.use(router)
app.use(VueGridLayout)

app.use(ElementPlus, {locale: zhCn})
useElIcon(app)

// 注册指令
directive(app);

app.mount('#app')
